package com.fuchuang.seckillsystem.controller;

import com.fuchuang.seckillsystem.entity.Account;
import com.fuchuang.seckillsystem.entity.MyUserDetails;
import com.fuchuang.seckillsystem.service.IAccountService;
import com.fuchuang.seckillsystem.vo.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("account")
public class AccountController {
    
    @Autowired
    private IAccountService accountService;
    
    
    @GetMapping("user")
    public RespBean getAccount(@AuthenticationPrincipal MyUserDetails userDetails) {
        Account account = accountService.getAccountByUserId(userDetails.getId());
        return RespBean.success(account);
    }
    
    @GetMapping("bank")
    @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
    public RespBean getBankAccount() {
        Account account = accountService.getBankAccount();
        return RespBean.success(account);
    }
    
}
